package com.jingan.nursinghome.regulatory.http;

import android.app.Activity;
import android.util.Log;

import com.jingan.nursinghome.regulatory.data.MicrometerTable;
import com.jingan.nursinghome.regulatory.model.BaseTimuModel;
import com.jingan.nursinghome.regulatory.model.Images;
import com.jingan.nursinghome.regulatory.model.Jinlaoyuang;
import com.jingan.nursinghome.regulatory.model.Linkup;
import com.jingan.nursinghome.regulatory.model.Qfinfo;
import com.jingan.nursinghome.regulatory.model.QfinfoTopic;
import com.jingan.nursinghome.regulatory.model.Topicinfo;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import cn.android.support.v7.lib.sin.crown.base.BaseListenner;
import cn.android.support.v7.lib.sin.crown.builder.HttpBuilder;
import cn.android.support.v7.lib.sin.crown.dialog.ProgressDailog;
import cn.android.support.v7.lib.sin.crown.utils.BeanUtils;
import cn.android.support.v7.lib.sin.crown.utils.CacheUtils;
import cn.android.support.v7.lib.sin.crown.utils.HttpUtils;
import cn.android.support.v7.lib.sin.crown.utils.JSONObjectUtils;

/**
 * Created by 彭治铭 on 2017/10/20.
 */

public class Http {
    private Http() {
    }

    static Http http;

    public static Http getInstance() {
        if (http == null) {
            http = new Http();
        }
        return http;
    }

    //    String base = "http://meetuuu.com/yanlaoapperban/";
    String base = "http://shptweilao.org.cn:29080/putuoapp/";
    String urlLogin = base + "qwadmin/index.php/Home/Yanglaoapi/Login";//登陆
    String urlJly = base + "qwadmin/index.php/Home/Organs";//敬老院
    String urlLink = base + "qwadmin/index.php/Home/Linkup";//主要沟通人员(养老机构人员，绑定养老机构id)
    String urlLink1 = base + "qwadmin/index.php/Home/Pgry";//评估人员。通用。不绑定养老机构。
    String urlToplist = base + "qwadmin/index.php/Home/Topiclist";//套题列表名称
    String urlQian = base + "qwadmin/index.php/Home/Topiclist/topicinfo";//千分表日常表题目

    String urlCommitQF = base + "qwadmin/index.php/Home/Qianfenlist/speciallist";//千分表提交
    String urlHostZhen = base + "qwadmin/index.php/Home/QfbRectificationsubject";//千分表历史整改


    //String urlqfinfo = base + "qwadmin/index.php/Home/Qfview/qfinfo";//查看巡检信息
    public String urlqfinfo = base + "qwadmin/index.php/Home/Qujiduan";//查看巡检信息
    String urlqfinftopiclist = base + "qwadmin/index.php/Home/Qfview/topiclist";//查看巡检题目列表详情
    String urlqfinfCae = base + "qwadmin/index.php/Home/Qfview/qfiptinfos";//查看巡检信息,签名，主要沟通人员，备注
    String urlqfimgs = base + "qwadmin/index.php/Home/Qfview/qfimgs";//图片
    public String qianming = base + "qwadmin";//签名图片前缀
    public String img = base + "qwadmin";//图片

    public String timuImg = base + "qwadmin/index.php/Home/Topicimglist";//题目图片。返回id。

    public void UploadTimuImg(final Activity activity, List<Topicinfo> topicinfos, final BaseListenner bs) {
        final int[] count = {0, 0};
        for (int i = 0; i < topicinfos.size(); i++) {
            for (int j = 0; j < topicinfos.get(i).getSelectList().size(); j++) {
                String path = topicinfos.get(i).getSelectList().get(j).getPath();
                File file = new File(path);
                if (file.exists()) {
                    count[0]++;
                    if (count[0] == 1) {
                        //ProgressDailog.buider(activity);
                    }
                    upFile(activity, file, topicinfos.get(i), j, new BaseListenner() {
                        @Override
                        public void onResult(Object result) {
                            count[1]++;
                            if (count[1] == count[0]) {
                                //所有请求都完成
                                bs.onResult(null);
                                //ProgressDailog.tear(activity);
                            }
                        }
                    });
                }
            }
        }
        if (count[0] == 0 && count[1] == 0) {
            //没有图片，没有请求
            bs.onResult(null);
        }
    }

    private void upFile(Activity activity, File file, final Topicinfo topicinfo, final int j2, final BaseListenner baseListenner) {
        HttpBuilder.Builder(timuImg).addFile("topicimg", file).execute(activity, new HttpUtils.RequestCallBack() {
            @Override
            public boolean isCacle() {
                return false;
            }

            @Override
            public boolean isLoading() {
                return false;
            }

            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                Log.e("test", "数据:\t" + result);

                HttpUtils.BaseBean baseBean = new HttpUtils.BaseBean();
                baseBean = BeanUtils.getInstance().getBean(baseBean, result);
                if (baseBean.isSuccess()) {
                    String id = baseBean.getList();
                    Log.e("test", "j2等于:\t" + j2);
                    if (j2 == 0) {
                        topicinfo.setTopic_imgyi(id);
                        Log.e("test", "第一张:\t" + topicinfo.getTopic_imgyi());
                    } else if (j2 == 1) {
                        topicinfo.setTopic_imger(id);
                        Log.e("test", "第二张:\t" + topicinfo.getTopic_imger());
                    } else if (j2 == 2) {
                        topicinfo.setTopic_imgsan(id);
                        Log.e("test", "第三张:\t" + topicinfo.getTopic_imgsan());
                    }
                }
                baseListenner.onResult(null);
                return super.onSuccess(activity, result);
            }

            @Override
            public HttpUtils.BaseBean onFailure(Activity activity, String result) {
                Log.e("test", "图片上传失败:\t" + result);
                baseListenner.onResult(null);
                return super.onFailure(activity, result);
            }

        });
    }


    //登陆
    public void Login(String account, String pwd, HttpUtils.RequestCallBack callBack) {
        Map<String, String> map = new HashMap<>();
        map.put("account", account);
        map.put("pwd", pwd);
        HttpUtils.getInstance().sendPost(urlLogin, map, callBack);
    }

    //获取敬老院
    public void getJly() {
        HttpUtils.getInstance().sendGet(urlJly, null, new HttpUtils.RequestCallBack<HttpUtils.BaseBean>() {

            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                try {
                    Log.e("test", "敬老院数据:\t\n" + result);
                    JSONArray jsonArray = new JSONArray(result);
                    MicrometerTable.jlys.clear();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        Jinlaoyuang jinlaoyuang = (Jinlaoyuang) JSONObjectUtils.getInstance().getBean(jsonObject, Jinlaoyuang.class);
                        MicrometerTable.jlys.add(jinlaoyuang);
                    }
                    //缓存敬老院数据
                    CacheUtils.getInstance().put(MicrometerTable.getInstance().getJLYMark(), result);
                } catch (JSONException e) {
                    Log.e("test", "敬老院json数据获取异常:\t" + e.getMessage());
                }
                return null;
            }

            @Override
            public HttpUtils.BaseBean onFailure(Activity activity, String result) {
                Log.e("test", "敬老院数据失败:\t" + result);
                try {
                    String string = CacheUtils.getInstance().getAsString(MicrometerTable.getInstance().getJLYMark());
                    if (string == null) {
                        return null;
                    }
                    JSONArray jsonArray = new JSONArray(string);
                    MicrometerTable.jlys.clear();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        Jinlaoyuang jinlaoyuang = new Jinlaoyuang();
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        jinlaoyuang.setId(jsonObject.getString("id"));
                        jinlaoyuang.setName(jsonObject.getString("name"));
                        MicrometerTable.jlys.add(jinlaoyuang);
                    }
                } catch (JSONException e) {
                    Log.e("test", "敬老院json数据获取异常2:\t" + e.getMessage());
                }
                return null;
            }
        });
    }


    //获取主要沟通人员
    public void getLinkUP(String oid, final BaseListenner<List<Linkup>> baseListenner) {
        Map<String, String> params = new HashMap<>();
        params.put("oid", oid);
        HttpUtils.getInstance().sendPost(urlLink, params, new HttpUtils.RequestCallBack<HttpUtils.BaseBean>() {

            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                try {
                    //Log.e("test","数据:\t\n"+result);
                    JSONArray jsonArray = new JSONArray(result);
                    MicrometerTable.linkups.clear();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        Linkup linkup = (Linkup) JSONObjectUtils.getInstance().getBean(jsonObject, Linkup.class);
                        MicrometerTable.linkups.add(linkup);
                    }
                    baseListenner.onResult(MicrometerTable.linkups);
                    //缓存敬老院数据
                    CacheUtils.getInstance().put(MicrometerTable.getInstance().getLinkUPMark(), result);
                } catch (JSONException e) {
                    Log.e("test", "主要沟通人员json数据获取异常:\t" + e.getMessage());
                }
                return null;
            }

            @Override
            public HttpUtils.BaseBean onFailure(Activity activity, String result) {
                try {
                    String string = CacheUtils.getInstance().getAsString(MicrometerTable.getInstance().getLinkUPMark());
                    if (string == null) {
                        return null;
                    }
                    JSONArray jsonArray = new JSONArray(string);
                    MicrometerTable.linkups.clear();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        Linkup linkup = (Linkup) JSONObjectUtils.getInstance().getBean(jsonObject, Linkup.class);
                        MicrometerTable.linkups.add(linkup);
                    }
                    baseListenner.onResult(MicrometerTable.linkups);
                } catch (JSONException e) {
                    Log.e("test", "主要沟通人员json数据获取异常2:\t" + e.getMessage());
                }
                return null;
            }
        });
    }

    //获取评估人员
    public void getLinkUP1() {
        Map<String, String> params = new HashMap<>();
        HttpUtils.getInstance().sendPost(urlLink1, params, new HttpUtils.RequestCallBack<HttpUtils.BaseBean>() {

            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                try {
                    Log.e("test", "评估人员数据:\t\n" + result);
                    JSONArray jsonArray = new JSONArray(result);
                    MicrometerTable.getInstance().linkups1.clear();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        Linkup linkup = (Linkup) JSONObjectUtils.getInstance().getBean(jsonObject, Linkup.class);
                        MicrometerTable.getInstance().linkups1.add(linkup);
                    }
                    Log.e("test", "评估人员个数:\t" + MicrometerTable.getInstance().linkups1.size());
                    //缓存敬老院数据
                    CacheUtils.getInstance().put(MicrometerTable.getInstance().getLinkUPMark(), result);
                } catch (JSONException e) {
                    Log.e("test", "评估人员json数据获取异常:\t" + e.getMessage());
                }
                return null;
            }

            @Override
            public HttpUtils.BaseBean onFailure(Activity activity, String result) {
                try {
                    String string = CacheUtils.getInstance().getAsString(MicrometerTable.getInstance().getLinkUPMark());
                    if (string == null) {
                        return null;
                    }
                    JSONArray jsonArray = new JSONArray(string);
                    MicrometerTable.getInstance().linkups1.clear();
                    for (int i = 0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                        Linkup linkup = (Linkup) JSONObjectUtils.getInstance().getBean(jsonObject, Linkup.class);
                        MicrometerTable.getInstance().linkups1.add(linkup);
                    }
                } catch (JSONException e) {
                    Log.e("test", "评估人员json数据获取异常2:\t" + e.getMessage());
                }
                return null;
            }
        });
    }

    //获取题目模块
    public void getToplist() {
        HttpBuilder.Builder(urlToplist).addParam("uid", MicrometerTable.getInstance().getUser().getId()).execute(null, new HttpUtils.RequestCallBack<String>() {
            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                //Log.e("test","题目模块：\t"+result);
                return super.onSuccess(activity, result);
            }

            @Override
            public boolean isCacle() {
                return true;
            }

            @Override
            public boolean baseBean(HttpUtils.BaseBean baseBean) {
                try {
                    Log.e("test", "题目模块数据:\t" + baseBean.getResult());
                    JSONArray array = new JSONArray(baseBean.getResult());
                    MicrometerTable.names.clear();
                    for (int i = 0; i < array.length(); i++) {
                        String name = array.getJSONObject(i).getString("name");
                        MicrometerTable.names.add(name);
                        //Log.e("test","模块名称:\t"+MicrometerTable.names.get(i));
                    }
                } catch (Exception e) {
                    Log.e("test", "题目模块JSON解析异常:\t" + e.getMessage());
                }
                return super.baseBean(baseBean);
            }
        });
    }


    //千分表题目
    public void getTopicInfoList(Activity activity, final String name, final String oid, final BaseListenner<List<Topicinfo>> baseListenner, final BaseListenner<String> fail) {
        HttpBuilder.Builder(urlQian).addParam("name", name).addParam("oid", oid).setShowParams(true).execute(activity, new HttpUtils.RequestCallBack<BaseTimuModel>() {

            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                Log.e("test", "题目数据:\t" + result);
                return super.onSuccess(activity, result);
            }

            @Override
            public boolean isCacle() {
                return true;
            }

            @Override
            public String getCacleMark() {
                return urlQian + name;//题目类型缓存标志。
            }

            @Override
            public boolean baseBean(HttpUtils.BaseBean baseBean) {
                //Log.e("test","数据:\t"+baseBean.toString());
                if (baseBean.isSuccess()) {
                    return true;
                } else {
                    if (fail != null) {
                        fail.onResult(baseBean.getErrmsg());
                    }
                    return false;
                }
            }

            @Override
            public boolean isList() {
                return true;
            }

            @Override
            public void finish(List<BaseTimuModel> list) {
                super.finish(list);
                List<Topicinfo> topicinfos = new ArrayList<>();
                for (int i = 0; i < list.size(); i++) {
                    String data = list.get(i).getData();
                    String subjectcategory_name = list.get(i).getSubjectcategory_name();
                    if (data != null && !data.trim().equals("null") && !data.trim().equals("")) {
                        JSONArray jsonArray = null;
                        try {
                            jsonArray = new JSONArray(data);
                        } catch (JSONException e) {
                            Log.e("test", "千分表题目JSON数据解析异常:\t" + e.getMessage());
                        }
                        List<Topicinfo> topicinfos2 = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topicinfo.class);
                        topicinfos2.get(0).setSubjectcategory_name(subjectcategory_name);
                        topicinfos.addAll(topicinfos2);
                    }
                }
                baseListenner.onResult(topicinfos);
//                Log.e("test","题目总数:\t"+list.size()+"\t题目总分:\t"+list.get(0).getTotal_score());
//                int score=0;
//                for(int i=0;i<list.size();i++){
//                    Log.e("test","type:\t"+list.get(i).getTopic_type()+"\t"+(list.get(i).getTopic_type()==null)+"\t题目：\t"+list.get(i).getTtitle());
//                    score+=list.get(i).getTopic_score();
//                }
//                Log.e("test","总分:\t"+score);
            }
        });
    }

    //千分表题目【历史整改记录】
    public void getTopicInfoListHost(Activity activity, String oid, String stname, final BaseListenner<List<Topicinfo>> baseListenner, final BaseListenner<String> fail) {
        HttpBuilder.Builder(urlHostZhen).addParam("oid", oid).addParam("stname", stname).setShowParams(true).execute(activity, new HttpUtils.RequestCallBack<BaseTimuModel>() {

            @Override
            public boolean isLoading() {
                return false;
            }

            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                Log.e("test", "历史整改:\t" + result);
                return super.onSuccess(activity, result);
            }

            @Override
            public HttpUtils.BaseBean onFailure(Activity activity, String result) {
                Log.e("test", "历史整改失败:\t" + result);
                return super.onFailure(activity, result);
            }

            @Override
            public boolean baseBean(HttpUtils.BaseBean baseBean) {
                //Log.e("test","数据:\t"+baseBean.toString());
                if (baseBean.isSuccess()) {
                    return true;
                } else {
                    if (fail != null) {
                        fail.onResult(baseBean.getErrmsg());
                    }
                    return false;
                }
            }

            @Override
            public boolean isList() {
                return true;
            }

            @Override
            public void finish(List<BaseTimuModel> list) {
                super.finish(list);
                List<Topicinfo> topicinfos = new ArrayList<>();
                for (int i = 0; i < list.size(); i++) {
                    String data = list.get(i).getData();
                    String subjectcategory_name = list.get(i).getSubjectcategory_name();
                    if (data != null && !data.trim().equals("null") && !data.trim().equals("")) {
                        JSONArray jsonArray = null;
                        try {
                            jsonArray = new JSONArray(data);
                        } catch (JSONException e) {
                            Log.e("test", "千分表题目JSON数据解析异常[历史整改]:\t" + e.getMessage());
                        }
                        List<Topicinfo> topicinfos2 = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topicinfo.class);
                        topicinfos2.get(0).setSubjectcategory_name(subjectcategory_name);
                        Log.e("test", "历史整改分类:\t" + subjectcategory_name);
                        topicinfos.addAll(topicinfos2);
                    }
                }
                baseListenner.onResult(topicinfos);
                //Log.e("test", "历史题目总数:\t" + list.size() + "\t题目总分:\t" + list.get(0).getTotal_score());
//                int score = 0;
//                for (int i = 0; i < topicinfos.size(); i++) {
//                    //Log.e("test", "type:\t" + list.get(i).getTopic_type() + "\t" + (list.get(i).getTopic_type() == null) + "\t题目：\t" + list.get(i).getTtitle());
//                    score += topicinfos.get(i).getTopic_score();
//                }
                //Log.e("test", "总分:\t" + score);
            }
        });
    }

    //千分表巡检信息提交
    public void CommitQF(Map map, Map file, final BaseListenner<String> baseListenner) {

//        Iterator it = map.entrySet().iterator();
//        while (it.hasNext()) {
//            Map.Entry entry = (Map.Entry) it.next();
//            String key = entry.getKey().toString();
//            String value = entry.getValue().toString();
//            Log.e("test", "键:\t" + key + "\t值:\t" + value);//打印params提交参数。
//        }

        HttpUtils.getInstance().sendPostFile(urlCommitQF, map, file, new HttpUtils.RequestCallBack() {

            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                String mession = "提交失败";
                try {
                    Log.e("test", "千分表提交：\t" + result + "\t结束");
                    JSONObject jsonObject = new JSONObject(result);
                    if (jsonObject.getString("code").equals("0")) {
                        //专项表巡检信息提交成功
                        Log.e("test", "提交成功");
                        mession = "提交成功";
                    } else {
                        mession = "提交错误:\t" + jsonObject.getString("errmsg");
                        Log.e("test", "千分表提交错误：\t" + jsonObject.getString("errmsg"));
                    }
                } catch (JSONException e) {
                    mession = "提交错误:\t" + e.getMessage();
                    Log.e("test", "千分表提交JSON数据解析出错:\t" + e.getMessage());
                }
                if (baseListenner != null) {
                    baseListenner.onResult(mession);
                }
                return null;
            }

            @Override
            public HttpUtils.BaseBean onFailure(Activity activity, String result) {
                if (baseListenner != null) {
                    if (result.contains("No address associated with hostname") || result.contains("No address") || result.contains("with hostname")) {
                        baseListenner.onResult("提交失败，没有网络");
                    } else {
                        baseListenner.onResult("服务器异常:\t" + result);
                    }
                }
                Log.e("test", "千分表提交异常2：\t" + result);
                return null;
            }
        });
    }

    /**
     * 获取巡检信息
     *
     * @param activity
     * @param oid           敬老院id
     * @param baseListenner
     */
    public void qfinfo(Activity activity, final String oid, final BaseListenner<List<Qfinfo>> baseListenner) {
        HttpBuilder.Builder(urlqfinfo).addParam("oid", oid).setShowParams(false).execute(activity, new HttpUtils.RequestCallBack<Qfinfo>() {

            @Override
            public boolean isCacle() {
                return true;
            }

            @Override
            public String getCacleMark() {
                return urlqfinfo + oid;
            }

            @Override
            public boolean baseBean(HttpUtils.BaseBean baseBean) {
                return baseBean.isSuccess();
            }

            @Override
            public boolean isList() {
                return true;
            }

            @Override
            public void finish(List<Qfinfo> list) {
                super.finish(list);
                if (baseListenner != null) {
                    baseListenner.onResult(list);
                }
            }
        });
    }

    /**
     * 获取信息信息详情题目列表
     *
     * @param activity
     * @param iid      巡检信息id
     */
//    public void qfinfotopiclist(Activity activity, String iid, final BaseListenner<List<QfinfoTopic>> baseListenner) {
//        HttpBuilder.Builder(urlqfinftopiclist).addParam("iid", iid).execute(activity, new HttpUtils.RequestCallBack<BaseTimuModel>() {
//            @Override
//            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
//                Log.e("test","巡检信息题目详情:\t"+result);
//                return super.onSuccess(activity, result);
//            }
//
//            @Override
//            public boolean baseBean(HttpUtils.BaseBean baseBean) {
//                return baseBean.isSuccess();
//            }
//
//            @Override
//            public boolean isList() {
//                return true;
//            }
//
//            @Override
//            public void finish(List<BaseTimuModel> list) {
//                super.finish(list);
//                List<QfinfoTopic> topicinfos = new ArrayList<>();
//                for (int i = 0; i < list.size(); i++) {
//                    String data = list.get(i).getData();
//                    String subjectcategory_name = list.get(i).getSubjectcategory_name();
//                    if (data != null && !data.trim().equals("null") && !data.trim().equals("")) {
//                        JSONArray jsonArray = null;
//                        try {
//                            jsonArray = new JSONArray(data);
//                        } catch (JSONException e) {
//                            Log.e("test", "千分表题目JSON数据解析异常:\t" + e.getMessage());
//                        }
//                        List<QfinfoTopic> topicinfos2 = JSONObjectUtils.getInstance().getArrayList(jsonArray, QfinfoTopic.class);
//                        topicinfos2.get(0).setSubjectcategory_name(subjectcategory_name);
//                        topicinfos.addAll(topicinfos2);
//                    }
//                }
//                baseListenner.onResult(topicinfos);
//            }
//        });
//    }
    public void qfinfotopiclist(Activity activity, String iid, final BaseListenner<List<Topicinfo>> baseListenner) {
        HttpBuilder.Builder(urlqfinftopiclist).addParam("iid", iid).execute(activity, new HttpUtils.RequestCallBack<BaseTimuModel>() {
            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                Log.e("test", "巡检信息题目详情:\t" + result);
                return super.onSuccess(activity, result);
            }

            @Override
            public boolean baseBean(HttpUtils.BaseBean baseBean) {
                return baseBean.isSuccess();
            }

            @Override
            public boolean isList() {
                return true;
            }

            @Override
            public void finish(List<BaseTimuModel> list) {
                super.finish(list);
                List<Topicinfo> topicinfos = new ArrayList<>();
                for (int i = 0; i < list.size(); i++) {
                    String data = list.get(i).getData();
                    String subjectcategory_name = list.get(i).getSubjectcategory_name();
                    if (data != null && !data.trim().equals("null") && !data.trim().equals("")) {
                        JSONArray jsonArray = null;
                        try {
                            jsonArray = new JSONArray(data);
                        } catch (JSONException e) {
                            Log.e("test", "千分表题目JSON数据解析异常:\t" + e.getMessage());
                        }
                        List<Topicinfo> topicinfos2 = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topicinfo.class);
                        topicinfos2.get(0).setSubjectcategory_name(subjectcategory_name);
                        topicinfos.addAll(topicinfos2);
                    }
                }
                baseListenner.onResult(topicinfos);
            }
        });
    }

    /**
     * 获取信息信息签名，备注，主要沟通人员
     *
     * @param activity
     * @param iid      巡检信息id
     */
    public void qfinfoCase(Activity activity, String iid, final BaseListenner<List<Qfinfo>> baseListenner) {
        HttpBuilder.Builder(urlqfinfCae).addParam("iid", iid).execute(activity, new HttpUtils.RequestCallBack<Qfinfo>() {
            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                //Log.e("test","巡检信息成功:\t"+result);
                return super.onSuccess(activity, result);
            }

            @Override
            public boolean baseBean(HttpUtils.BaseBean baseBean) {
                return baseBean.isSuccess();
            }

            @Override
            public boolean isList() {
                return true;
            }

            @Override
            public void finish(List<Qfinfo> list) {
                super.finish(list);
                if (baseListenner != null) {
                    baseListenner.onResult(list);
                }
            }
        });
    }


    /**
     * 获取图片信息
     *
     * @param activity
     * @param iid      巡检信息id
     */
    public void qfinfoImg(Activity activity, String iid, final BaseListenner<List<Images>> baseListenner) {
        HttpBuilder.Builder(urlqfimgs).addParam("iid", iid).execute(activity, new HttpUtils.RequestCallBack<Images>() {

            @Override
            public HttpUtils.BaseBean onSuccess(Activity activity, String result) {
                //Log.e("test","图片数据:\t"+result);
                return super.onSuccess(activity, result);
            }

            @Override
            public boolean baseBean(HttpUtils.BaseBean baseBean) {
                return baseBean.isSuccess();
            }

            @Override
            public boolean isList() {
                return true;
            }

            @Override
            public void finish(List<Images> list) {
                super.finish(list);
                if (baseListenner != null) {
                    baseListenner.onResult(list);
                }
            }
        });
    }

}
